#!/usr/bin/bash

if [[ $1 == "tar" ]]; then
    cd ../..
    if [ -f ./vkb.tar ]; then
        rm vkb.tar
    fi
    tar -cf vkb.tar virtkeyboard/
    cp virtkeyboard/skin/install.sh .
    echo "完成打包，请连同 install.sh 脚本一同传送"
    exit
fi

path_bin="/home/i5/nut/bin/"
path_vkb=${path_bin}"/virtkeyboard"
path_app="/home/i5/nut/app/"
path_skin=${path_app}"/i5App.VirtKeyboard"

dpkg -l python3-virtkey
if [ $? != 0 ] ; then
	echo 'No package python3-virtkey found, apt-get it.'
	sudo apt-get update
	sudo apt-get install python3-virtkey
fi

dpkg -l python3-pyqt5
if [ $? != 0 ] ; then
	echo 'No package python3-pyqt5 found, apt-get it.'
	sudo apt-get update
	sudo apt-get install python3-pyqt5
fi

tar -xf vkb.tar
test -d $path_app || mkdir $path_app

test -d $path_skin && rm -rf $path_skin

cp -r virtkeyboard/skin/i5os_vkb $path_app
mv ${path_app}/i5os_vkb $path_skin

test -d $path_vkb && rm -rf $path_vkb
mv virtkeyboard/ $path_bin

cd $path_skin
sh start.sh